import React, { Component } from 'react'
import { connect } from 'react-redux'
import { Redirect } from 'react-router-dom'
import { NavBar, Icon, InputItem, List, TextareaItem, Button } from 'antd-mobile'
import AvatarSelect from '../../component/avatarSelect'
import { actionCreator } from '../../store/user'

class Bossinfo extends Component {
  constructor(props) {
    super(props)
    this.state = {
      title: '高级前端开发',
      desc: '前端精通',
      company: '阿里巴巴',
      money: '25k-40k',
      avatar: ''
    }
  }
  handleChange(key, value) {
    this.setState({
      [key]: value
    })
  }
  update() {
    this.props.update(this.state)
  }
  render() {
    const { redirectTo, location } = this.props
    return (
      <List>
        {redirectTo && redirectTo !== location.pathname ? <Redirect to={redirectTo}></Redirect> : null}
        <NavBar
          mode="dark"
          leftContent="Back"
          rightContent={[
            <Icon key="0" type="search" style={{ marginRight: '16px' }} />,
            <Icon key="1" type="ellipsis" />,
          ]}
        >boss完善信息页</NavBar>
        <AvatarSelect
          onClick={(ele, index) => {
            this.handleChange('avatar', ele.text)
          }}
        >
        </AvatarSelect>
        <InputItem
          onChange={(v) => { this.handleChange('title', v) }}
        >招聘职位</InputItem>
        <InputItem
          onChange={(v) => { this.handleChange('company', v) }}
        >公司名称</InputItem>
        <InputItem
          onChange={(v) => { this.handleChange('money', v) }}
        >职位薪资</InputItem>
        <TextareaItem
          title={`职位要求`}
          rows={3}
          onChange={(v) => { this.handleChange('desc', v) }}
        ></TextareaItem >
        <Button
          type='primary'
          onClick={() => { this.update() }}
        >保存</Button>
      </List>
    )
  }
}
const mapState = (state) => ({
  redirectTo: state.user.redirectTo
})
const mapDispatch = (dispatch) => ({
  update(data) {
    dispatch(actionCreator.update(data))
  }
})
export default connect(mapState, mapDispatch)(Bossinfo)